
define([
	'../../Shop/module/STH_main.js',
    'kindeditor'
], function(main){
	
	return {

	
	/**--text类型start--*/
	
	    //加入text类型模块
	    textAddM:function(con){	    	
	    	var _this=this,
	    	    key=con.key,
	    	    order = con.order,
	    	    htmlStr=(con.item_list[0].html.length>=1)?(con.item_list[0].html):"",
                htmlStr = decodeURIComponent(htmlStr);
	    	    newPanel=main.getPanel("text"),	                        
	            newEdit=main.getEdit("text");
	            
		        //属性操作
		        $(newPanel).attr("order",order);
		        $(newPanel).attr("key",key);
		        $(newEdit).attr("key",key);
//		        console.log(htmlStr);
		        $(newPanel).find(".textareas").html(htmlStr);	
				
				$(newEdit).css("display","none");
				
				//延时顺序重定位
		        var edLength=$(".hb_box .panel-comp").length;
				if($(".hb_box .panel-comp").length<1 || order>parseInt($(".hb_box .panel-comp").eq(edLength-1).attr("order"))){
			        	$(".hb_box").append(newPanel);
			    }else if(order < parseInt($(".hb_box .panel-comp").eq(0).attr("order"))){
			       		$(".hb_box").prepend(newPanel);
			    }else{
			       	for(var r=0; r<edLength; r++){
			       		if(order > parseInt($(".hb_box .panel-comp").eq(r).attr("order")) && order < parseInt($(".hb_box .panel-comp").eq(r+1).attr("order"))){
			       				$(".hb_box .panel-comp").eq(r).after(newPanel);
			       				break;
			       		}	       			
			       	}
			    }
	            $(".edit-panel").append(newEdit);	           
	            _this.textActive(newPanel,newEdit,key);
	    },
	
        //text类型的常规操作
        textActive:function(thisPanel,thisEdit,key){
        	var _this=this,
        	    _textStr=$(thisPanel).find(".textareas").html(),
             	K = KindEditor;
            
            if(typeof(g_data[key].item_list[0])=="undefined"){
            	g_data[key].item_list[0] = {"html":""};
            }
             	
            $(thisEdit).find(".ckeditor_standard").attr("id",'ckeditor_standard'+key);
             
   			edit_Obj=K.create('#ckeditor_standard'+key, {
					allowFileManager : false,
					minHeight:250,
					width:500,
				    uploadJson: '../../Api/upload_ajax.ashx?action=EditorFile&IsWater=1',
                    fileManagerJson: '../../Api/upload_ajax.ashx?action=ManagerFile',
					items:[
					        'undo', 'redo', '|', 
					        'justifyleft', 'justifycenter', 'justifyright', 'clearhtml',
					        'fontsize', 'forecolor','hilitecolor','bold',
					        'italic', 'underline','strikethrough','link', 'unlink','|',
					        'image','fullscreen'
					],
					fullscreenShortcut:true,					
					afterBlur : function() {
						this.sync();
						var htmlStr = this.html();
						
						//if(this.isEmpty()){
						//	$(thisPanel).find('.textareas').html($(main.getPanel("text")).find(".textareas").html());
						//	g_data[key].item_list[0].html="";
						//}else{
							$(thisPanel).find('.textareas').html(htmlStr);
							g_data[key].item_list[0].html=encodeURIComponent(htmlStr);
						//}
		            	
					}
			});
			edit_Obj.html(decodeURIComponent(g_data[key].item_list[0].html));
            
			
			//调用主模板JS
		    main.saveClick();
		    main.moduleActive();
	        main.dragEdit();
        },
        
	/**--text类型end--*/
	
	


	}
});

